<?php

namespace app\modules\api\controllers;

use app\models\SendAuction;
use ac\component\tool\Tool;
use ac\component\exception\ErrMap;
use yii\helpers\Html;

/*送拍*/
class SendController extends AuthController
{

    /*列表*/
    public function actionList()
    {
        // P($this->userInfo);
        if(isset($this->get['page'])){
            $currPage = intval($this->get['page']?$this->get['page']:1);
        }else{
            $currPage = 1;
        }
        $pageSize = Tool::getPageSize();

        $sendAuction = new SendAuction;
        $count = $sendAuction::find()->where('member_id = :id', [':id' => $this->userInfo->member_id])->count();
        $sendAuctionList = $sendAuction::find()->where('{{%pj8_send_auction}}.member_id = :id', [':id' => $this->userInfo->member_id])
                        ->with('member')->with('goods')
                        ->orderBy(['id' => SORT_DESC])
                        ->offset($pageSize*($currPage-1))->limit($pageSize)
                        ->asArray()->all();
        $res = array(
            'list' => $sendAuctionList,
            'pageInfo' => array(
                'count' => intval($count),
                'currPage' => $currPage,
                'pageSize' => $pageSize,
            ),
        );
        // P($sendAuctionList);
        return Tool::showRes([0, '获取成功'], $res);
    }

    /*详情*/
    public function actionAuction()
    {
        $id = isset($this->get['id'])?$this->get['id']:'';
        if($id){
            $sendAuction = SendAuction::find()
                        ->where('id = :id', [':id' => $id])
                        ->asArray()->one();
            // P($sendAuction);
            if(!is_null($sendAuction)){
                // P($sendAuction);
                return Tool::showRes([0, '获取成功'], $sendAuction);
            };
        }
        return Tool::showRes(ErrMap::getError(10005));
    }

}
